package com.yd.app.service.pc.dicService;

import com.yd.app.mapper.DicMapper;
import com.yd.app.service.common.BaseService;
import com.yd.domain.business.GType;
import com.yd.domain.commom.PageModel;
import com.yd.domain.searchParam.DicParam;
import com.yd.domain.sys.Dic;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zy
 * @create 2018-03-07 17:44
 * @des 数据字典
 **/
@Service
public class DicService extends BaseService {
    @Autowired
    private DicMapper dicMapper;
    /**
     * @Author: zy
     * @Desc: 新增字典
     * @Date:  2018/3/7
     */
    public void addDic(Dic dic){
        dicMapper.addDic(dic);
    }
    /**
     * @Author: zy
     * @Desc:分页检索权限数据
     * @Date:  2018/3/7
     */
    public PageModel getDicList(DicParam dic, int pageIndex, int pageSize){
        PageModel pm=new PageModel();
        List<Dic> list=new ArrayList<>();
        list=dicMapper.searchDicList(dic,getStartRow(pageIndex,pageSize),pageSize);
        int count=0;
        if(pageIndex==1){
            //查询总条数
            count=dicMapper.searchDicCount(dic);
            pm.setCount(count);
        }
        pm.setList(list);
        return pm;
    }
    /**
     * @Author: zy
     * @Desc:   根据字典类型获取字典数据
     * @Date:  2018/3/8
     */
    public List<Dic> getDicCacheByType(String type) {
        List<Dic>dics= new ArrayList<>();
        dics= dicMapper.getDicListByType(type);
        return dics;
    }
    /**
     * @Author: zy
     * @Desc: 修改数据字典
     * @Date:  2018/3/8
     */
    public void updateDic(Dic dic) {
        dicMapper.updateDic(dic);
    }
    /**
     * @Author: zy
     * @Desc: 删除数据字典
     * @Date:  2018/3/8
     * @Param
     */
    public void deleteDic(String id) {
        dicMapper.deleteDic(id);
    }

    public List<GType> getGTypeList() {
        List<GType> list=dicMapper.getGTypeList();
        return list;
    }

    /**
     * 启用停用gtype
     * @param id
     * @param ifUse
     */
    public void enableGType(String id, boolean ifUse) {
        dicMapper.enableGType(id,ifUse);
    }

    /**
     * 添加
     * @param gType
     */
    public void addGType(GType gType) {
        dicMapper.addGType(gType);
    }

    public void updateGType(GType gType) {
        dicMapper.updateGTpye(gType);
    }
}
